php access multidimensional array by string

38

function get_multi($arr, $str) {
    foreach (explode('.', $str) as $key) {
        if (!array_key_exists($key, $arr)) {
            return NULL; 
        }
        $arr = $arr[$key];
    }

    return $arr;
}

Comments

Submit
0 Comments